<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="css/index.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/index.css"/>

		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css"/>
		<link rel="stylesheet" type="text/css" href="../css/mui.poppicker.css"/>
		<link rel="stylesheet" type="text/css" href="../css/lcs-pop.css"/>
		<link rel="stylesheet" type="text/css" href="css/empcss.css"/>
		<link rel="stylesheet" type="text/css" href="css/compatible.css"/>
		<script type="text/javascript">
			var setData = {date_type:"date", date:"today"};
		</script>
		<style>
			#container{
				height: 30vh;
				min-height: 250px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg ">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title">利润统计</h1>
		</header>
		<div class="mui-content">
		    
		
		<main id="content">
			<section class="mui-content financial-tab text-center" data-url='/api/order/profit_census'>
				<ul class="mui-row">
					<li class="mui-col-xs-6" onclick="tab(event, storeChange)"> <!--onclick="tab(event, paytype)"-->
						<p>门店</p>
						<div class="financial-subtab curStore" data-store="">
							<!-- <span data-name="all">全部途径</span>
							<span data-name="普通支付">普通支付</span>
							<span data-name="现金支付">现金支付</span>
							<span data-name="移动支付">移动支付</span>
							<span data-name="微信支付">微信支付</span>
							<span data-name="支付宝支付">支付宝支付</span>
							<span data-name="其它">其它</span> -->
						</div>
					</li>
					<li class="mui-col-xs-6" onclick="tab(event, changeDate)">
						<p>今日</p>
						<div class="financial-subtab">
							<span data-type="date" data-date="today">今天</span>
							<span data-type="date" data-date="yesterday">昨天</span>
							<span data-type="custom" data-date="week">本周</span>
							<span data-type="custom" data-date="month">本月</span>
							<span class="none" onclick="timeStep(event)">时间段</span>
						</div>
					</li>
				</ul>
			</section>
			<section class="mui-content container profit-info">
				<ul class="mui-row">
					<li class="mui-col-xs-6"><span>总收入</span><i class="total"></i></li>
					<li class="mui-col-xs-6 color"><span>总成本</span><i class="all_buy_price"></i></li>
					<li class="mui-col-xs-6"><span>总数量</span><i class="num"></i>件</li>
					<li class="mui-col-xs-6 color"><span>总利润</span><i class="profit"></i></li>
				</ul>
			</section>
			<section class="table container text-center profit-table table-col-5">
				
				
			</section>
			
			<div id="container"></div>

			<div id="popover" class="mui-popover">
				<div class="listdiv">
					<div class="mui-input-row borbot" >
						<label>开始时间:</label>
						<div class="place items">
							<button id='starttime' data-time="" onclick="changTime(event)" type="button" class="mui-btn mui-btn-blue mui-btn-outlined">开始时间</button>
						</div>
					</div> 
					<div class="mui-input-row borbot" >
						<label>结束时间:</label>
						<div class="place items">
							<button id='endtime' data-time="" onclick="changTime(event)" type="button" class="mui-btn mui-btn-blue mui-btn-outlined">结束时间</button>
						</div>
					</div>
					<button type="button" id="okbut" class="mui-btn mui-btn-blue mui-btn-block">确定</button>
				</div>
			</div>
		</main>
		</div>
	</body>
	<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/mui.min.js"></script>
	<script src="js/echarts.js"></script>
	<script src="../js/req.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>

	<script src="../js/mui.picker.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/city.data.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/commont.js"></script>
	<script type="text/javascript">
		var dom = document.getElementById("container");
		var myChart = echarts.init(dom);
		

		function fn(_data){
			
			var time = []
			var profit = []
			
			
			if(_data.length > 0){
				_data.forEach(function(cur, index){
					time.push(cur['time'].substr(5))
					profit.push(cur['profit_money'])
				})
			}
			
			//console.log(profit, time)
			
			var option = {
				xAxis: {
					type: 'category',
					data: time,
					splitLine:{
					　　show:true
					},
					name : '日期',
					nameLocation : 'start',
					nameTextStyle : {
						padding : [30, -20, 0, 0]
					},
					nameGap : 20,
					axisLine : {
						lineStyle : {
							color : '#5799B7'
						}
					}
				},
				yAxis: {
					type: 'value',
					name : '利润',
					axisLine : {
						lineStyle : {
							color : '#5799B7'
						}
					}
				},
				lineStyle : {
					color : '#5799B7'
				},
				itemStyle : {
					color : '#5799B7'
				},
				series: [{
					data: profit,
					type: 'line',
					//symbol : 'none',
					smooth: true
				}]
			};

			if(_data.length > 8){
				option['dataZoom'] = [{
					type: 'inside',
					show: true, //flase直接隐藏图形
					xAxisIndex: [0],
					left: '9%', //滚动条靠左侧的百分比
					bottom: -5,
					start: 0,//滚动条的起始位置
					end: 60 ,//滚动条的截止位置（按比例分割你的柱状图x轴长度）
				}]
			}
			
			return option
		}

		function requireData(_data){

			var store = $('.curStore').data('store');
			if(!!store){
				_data['data']['store_id'] = store
			}else{
				delete _data['data']['store_id']
			}
			_data['data'].access_token = acctoken()

			//console.log(_data)
			
			ajax(_data, function (res){
				var data = res.data
				
				$('.total').html(data.census['all_money'])
				$('.all_buy_price').html(data.census['all_buy_price'])
				$('.num').html(data.census['product_number'])
				$('.profit').html(data.census['profit_money'])
				
				
				
				var html = ['<div class="table-th table-border"><span class="table-td">日期</span><span class="table-td">数量</span><span class="table-td">收入</span><span class="table-td">成本</span><span class="table-td">利润</span></div>']
				
				setEcharts(myChart, data['group'], fn)
				data['group'].forEach((cur, index, array) => {
					var tpl = `<div class="table-tr"><span class="table-td">${cur['time'].substr(5)}</span><span class="table-td">${cur['product_number']}</span><span class="table-td">${cur['all_money']}</span><span class="table-td">${cur['buy_money']}</span><span class="table-td color1">${cur['profit_money']}</span>
					</div>`;
				
					html.push(tpl);
				})
				
				//html.push(`<div class="table-th table-border"><span class="table-td"><b>合计</b></span><span class="table-td"><b>${data['']}</b></span><span class="table-td"><b>${data['']}</b></span><span class="table-td"><b>${data['']}</b></span><span class="table-td"><b>${data['']}</b></span></div>`)
				
				$('.table').html(html.join(''));
			})
		}
		
		
		$(function (){
			requireData({
				url : '/api/order/profit_census',
				data : {
					date_type : 'date',
					date : 'today'
				}
			})
			
		})
	
		window.addEventListener("resize", () => {
			myChart.resize();
		});
	</script>
</html>
